package com.itheima.example.provider;

import com.itheima.example.common.model.User;
import com.itheima.example.common.service.UserService;
import com.itheima.weirpc.bootstrap.ProviderBootstrap;
import com.itheima.weirpc.config.RegistryConfig;
import com.itheima.weirpc.config.RpcConfig;
import com.itheima.weirpc.constant.RpcConstant;
import com.itheima.weirpc.model.ServiceMetaInfo;
import com.itheima.weirpc.model.ServiceRegisterInfo;
import com.itheima.weirpc.registry.LocalRegistry;
import com.itheima.weirpc.registry.Registry;
import com.itheima.weirpc.registry.RegistryFactory;
import com.itheima.weirpc.server.HttpServer;
import com.itheima.weirpc.server.VertxHttpServer;
import com.itheima.weirpc.RpcApplication;
import com.itheima.weirpc.server.tcp.VertxTcpServer;

import java.util.ArrayList;
import java.util.List;

/**
 * ClassName: ProviderExample
 * Package: com.itheima.example.provider
 * Description:
 *
 * @Author 看到风
 * @Create 2024/11/23 19:36
 * @Version 1.0
 */
public class ProviderExample {
    public static void main(String[] args) {
        //要注册的服务
        List<ServiceRegisterInfo<?>> serviceMetaInfoList = new ArrayList<>();
        ServiceRegisterInfo<UserService> serviceRegisterInfo = new ServiceRegisterInfo<>(UserService.class.getName(),UserServiceImpl.class);
        serviceMetaInfoList.add(serviceRegisterInfo);

        //服务提供者初始化
        ProviderBootstrap.init(serviceMetaInfoList);


//        //PRC 框架初始化
//        RpcApplication.init();
//
//        //注册服务
//        String serviceName = UserService.class.getName();
//        LocalRegistry.register(UserService.class.getName(), UserServiceImpl.class);
//
//        RpcConfig rpcConfig = RpcApplication.getRpcConfig();
//        RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
//
//        Registry registry = RegistryFactory.getInstance(registryConfig.getRegistry());
//
//        ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
//        serviceMetaInfo.setServiceName(serviceName);
//        serviceMetaInfo.setServiceHost(rpcConfig.getServerHost());
//        serviceMetaInfo.setServicePort(rpcConfig.getServerPort());
//
//        try {
//            registry.register(serviceMetaInfo);
//        }catch (Exception e){
//            throw new RuntimeException(e);
//        }
//
//        //启动 web 服务
////        HttpServer httpServer = new VertxHttpServer();
////        httpServer.doStart(RpcApplication.getRpcConfig().getServerPort());
//
//        //启动TCP服务
//        VertxTcpServer vertxTcpServer = new VertxTcpServer();
//        vertxTcpServer.doStart(9999);
    }
}
